package com.cwl.pattern.策略模式;

/**
 * @program: pattern
 * @description:
 * @author: ChenWenLong
 * @create: 2019-06-24 14:03
 **/
public class Strategy {

    public static final String CASH_NORMAL = "正常收费";
    public static final String CASH_RETURN = "满300返100";
    public static final String CASH_REBATE = "打8折";
    /**
     * 功能描述:
     * 〈使用具体策略〉
     *
     * @params : [price, number, type]
     * @return : java.lang.Double
     * @author : cwl
     * @date : 2019/6/24 14:05
     */
    public static Double strategy(Double price, Double number, String type) {
        Double currentprice = price * number;
        CashContext cc =null ;
        switch (type){
            case CASH_NORMAL :
                cc =new CashContext(new CashNormal());
                break;
            case CASH_RETURN :
                cc =new CashContext(new CashReturn("300","100"));
                break;
            case CASH_REBATE :
                cc =new CashContext(new CashRebate("0.8"));
                break;
        }
        Double totalPrice =0D;
        totalPrice = cc.getResult(currentprice);
        return totalPrice;
    }
}
